(cond-expand
 (modules (import (only (chibi test) test-begin test-assert test test-error test-end)))
 (else #f))

(import (scheme base))
(import (scheme write))
(import (clock leap-seconds-list))

(test-begin "(clock leap-seconds-list")

(test-assert (procedure? leap-seconds-before-utc-day-alist))
(test-assert (procedure? leap-seconds-before-tai-second-alist))

(test-assert (procedure? set-open-leap-seconds-list-port!))
(test-assert (procedure? set-update-exception-handler!))

(test-assert (eqv? 'ok
                   (call-with-current-continuation
                    (lambda (k)
                      (with-exception-handler
                          (lambda (error) (k 'not-ok))
                        (lambda ()
                          (set-open-leap-seconds-list-port! (lambda () #f))
                          'ok))))))

(test-assert (eqv? 'ok
                   (call-with-current-continuation
                    (lambda (k)
                      (with-exception-handler
                          (lambda (error) (k 'ok))
                        (lambda ()
                          (set-open-leap-seconds-list-port! (lambda () 42))
                          'not-ok))))))

(test-assert (eqv? 'ok
                   (call-with-current-continuation
                    (lambda (k)
                      (set-update-exception-handler!
                       (lambda (error) (k 'ok)))
                      (set-open-leap-seconds-list-port! (lambda () 42))
                      'not-ok))))

(test-assert (eqv? 'ok
                   (call-with-current-continuation
                    (lambda (k)
                      (with-exception-handler
                          (lambda (object)
                            (k 'ok))
                        (lambda ()
                          (set-update-exception-handler!
                           (lambda (error) #t))
                          (set-open-leap-seconds-list-port! (lambda () 42))
                          'not-ok))))))

(test-end)
